package com.itheima.manage.interceptor;

import com.itheima.commons.pojo.entity.Admin;

/**
 * @author yaohu
 * @date 2021/12/17
 * @Version 1.0
 * @describe
 */
public class AdminThreadLocal {

    private static final ThreadLocal<Admin> threadLocal = new ThreadLocal<>();

    /**
     * 设置Admin到当前线程
     *
     * @param admin
     */
    public static void set(Admin admin) {
        threadLocal.set(admin);
    }

    /**
     * 从当前线程获取Admin
     *
     * @return
     */
    public static Admin get() {
        return threadLocal.get();
    }

    /**
     * 从当前线程删除Admin
     */
    public static void remove() {
        threadLocal.remove();
    }

    /**
     * 获取Admin的id
     *
     * @return
     */
    public static Long getAdminId() {
        return threadLocal.get().getId();
    }

    /**
     * 获取Admin的用户名
     *
     * @return
     */
    public static String getAdminUsername() {
        return threadLocal.get().getUsername();
    }
}
